import {DELETE, GET, POST} from "@/api/network";

export module Api {

    export module Meta {

        export enum SearchType {
            ALL = 0,
            USER = 1,
            STAR = 2,
            CLUB = 3,
            SYNC_CLUB = 4
        }

        export interface SearchRequest {
            search?:string
            type?:SearchType
        }

        export interface SearchResponse_Record {
            id:string
            name:string
            nick:string
            phone:string
            avatar:string
        }

        export interface SearchResponse_Item {
            records:Array<SearchResponse_Record>
        }

        export interface SearchResponse {
            type: SearchType
            results: Map<SearchType,SearchResponse_Item>
        }

        export function Search(ask: SearchRequest): Promise<SearchResponse> {
            return GET(
                '/meta/search',
                {
                    query:ask
                }
            )
        }



        export interface GetAdvertCalendarResponse_Advert {
            ad_id:string
            ad_title:string
            enable:boolean
            active:boolean
        }

        export interface GetAdvertCalendarResponse_DayAdvert {
            have: boolean
            advert: GetAdvertCalendarResponse_Advert
        }
        export interface GetAdvertCalendarResponse_Day {
            date: string
            adverts: Array<GetAdvertCalendarResponse_DayAdvert>
            enable:boolean
        }

        export interface GetAdvertCalendarResponse {
            weeks: Array<Array<GetAdvertCalendarResponse_Day>>
        }


        export interface GetAdvertCalendarRequest {
            date?:string
            type:number
        }

        export function GetAdvertCalendar(ask: GetAdvertCalendarRequest) : Promise<GetAdvertCalendarResponse> {

            let q = undefined;

            if(ask.date) {
                q = {date: ask.date}
            }
            return GET(`/meta/advert/calendar/${ask.type}`,{
                query:q,
            })
        }

        
        export interface CreateAdvertRequest {
            ad_id?:string
            ad_title:string
            ad_type:number
            link_type:number
            link:string
            callback:string
            begin_time:string
            end_time:string
            enable:boolean
            resource_type:number
            resource:string
            author:string
            ad_order:number

        }

        export interface CreateAdvertResponse {
            ad_id:string
        }

        export function CreateAdvert(ask: CreateAdvertRequest) : Promise<CreateAdvertResponse> {
            return POST(
                `/meta/advert/create`,
                ask,
            )
        }


        export interface GetAdvertRequest {
            ad_id:string
        }

        export interface GetAdvertResponse {
            ad_id:string
            ad_title:string
            ad_type:number
            link_type:number
            link:string
            callback:string
            begin_time:string
            end_time:string
            enable:boolean
            resource_type:number
            resource:string
            author:string
            ad_order:number
        }

        export function GetAdvert(ask: GetAdvertRequest): Promise<GetAdvertResponse> {
            return GET(
                `/meta/advert/info/${ask.ad_id}`
            )
        }

        export interface DeleteAdvertRequest {
            ad_id:string
        }

        export interface DeleteAdvertResponse {

        }

        export function DeleteAdvert(ask :DeleteAdvertRequest): Promise<DeleteAdvertResponse> {
            return DELETE(
                `/meta/advert/${ask.ad_id}`,
            )
        }

        export interface SetAdvertRequest {
            ad_id:string
            ad_title:string
            link_type:number
            link:string
            callback:string
            begin_time:string
            end_time:string
            enable:boolean
            resource_type:number
            resource:string
            author:string
            ad_order:number
        }

        export interface SetAdvertResponse {

        }

        export function SetAdvert(ask: SetAdvertRequest) : Promise<SetAdvertResponse> {
            return POST(
                `/meta/advert/edit/${ask.ad_id}`,
                ask
            )
        }

        export interface GetVersionListResponse_Item {
            version:string
            apk:string
            size:number
            md5:string
            auto_update:boolean
            create_time:string
            selected:boolean
        }
        
        export interface GetVersionListResponse {
            items:Array<GetVersionListResponse_Item>
        }
        
        export interface GetVersionListRequest {

        }

        export function GetVersionList(ask:GetVersionListRequest) : Promise<GetVersionListResponse> {
            return GET(
                `/meta/version/list`,
            )
        }

        export interface AddVersionRequest {
            version:string
            apk:string
            size:number
            md5:string
            auto_update:boolean
            message:string
        }
        
        export interface AddVersionResponse {

        }

        export function AddVersion(ask:AddVersionRequest) : Promise<AddVersionResponse> {
            return POST(
                `/meta/version/add`,
                ask,
            )
        }

        export interface SetVersionRequest {
            version:string
        }

        export interface SetVersionResponse {

        }

        export function SetVersion(ask:SetVersionRequest) : Promise<SetVersionResponse> {
            return POST(
                `/meta/version/edit`,
                ask,
            )
        }
    }


}

export default Api.Meta